﻿<!DOCTYPE html>
<html>
<head>
    <title>站点管理</title>
    $css()$js()
</head>
<body>
    <div id="pl_tpl">
        <div class="tabarea">
            <div class="tab_mini">
                <a class="current tabitem" href="javascript:;" group="basic">网站设置</a>
                <a class="tabitem" href="javascript:;" group="Profile">资料修改</a>
            </div>
            <div class="clearfix"></div>

            <select class="hidden" name="">
                ${tpls}
            </select>



            <div class="form autostyle">
                ${form}
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var plTpl = cms.$('pl_tpl');
        var tplTD = document.getElementsByName('field_tpl')[0].parentNode;
        var selector = plTpl.getElementsByTagName('SELECT')[0];
        tplTD.innerHTML = '';
        selector.setAttribute('field','tpl');
        selector.className = selector.className.replace('hidden', '');
        tplTD.appendChild(selector);

        var isCreate = location.hash.split('.')[1] == 'create';
        var postUrl = isCreate ? '?module=site&action=create' : '?module=site&action=edit';

        window.saveData = function () {
            if (cms.validator.validate()) {
                cms.xhr.jsonPost(postUrl, cms.json.toObject(document), function (json) {
                    if (json.result) {
                        parent.M.alert(json.message, function () {
                               location.reload();
                        });
                    } else {
                        parent.M.alert(json.message);
                    }
                });
            }
        };


        cms.$('btn').onclick = window.saveData;

        function initTab(cls) {
            var eles = document.getElementsByClassName(cls);
            cms.each(eles, function (i, e) {
                e.onclick = function () {
                    var group = e.getAttribute('group');
                    cms.each(document.getElementsByTagName('DL'), function (i2, e2) {
                        if (e2.getAttribute('group')) {
                            e2.style.display = e2.getAttribute('group') == group ? 'block' : 'none';
                        }
                    });
                    cms.each(eles, function (i3, e3) {
                        e3.className = e3 == e ? cls + ' current' : cls;
                    });
                };
            });
            eles[0].onclick();
        }

        initTab('tabitem');
    </script>
</body>
</html>